package com.example.makerspace.dao;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.makerspace.domain.CourseVideoDO;
import com.example.makerspace.dto.CourseVideoDTO;
import com.example.makerspace.mapper.CourseVideoMapper;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.List;

@Component
public class CourseVideoDAO extends BaseDAO<CourseVideoDO> {

    public final static String COURSE_ID = "course_id";
    public final static String CHAPTER_NUM = "chapter_num";

    @Resource
    private CourseVideoMapper courseVideoMapper;


    @PostConstruct
    public void init(){
        this.mapper = courseVideoMapper;
    }


    public CourseVideoDO selectDuplicate(CourseVideoDTO courseVideoDTO){
        return courseVideoMapper.selectOne(new QueryWrapper<CourseVideoDO>()
                .eq(COURSE_ID, courseVideoDTO.getCourseId())
                .eq(CHAPTER_NUM, courseVideoDTO.getChapterNum()));
    }

    public List<CourseVideoDO> selectByCourseId(Integer courseId) {
        return courseVideoMapper.selectList(new QueryWrapper<CourseVideoDO>()
                .eq(COURSE_ID, courseId).orderByAsc(CHAPTER_NUM));
    }
}
